package com.gxar.quick.ar.server.base.model.protocol.editor.unity;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.gxar.common.utils.JacksonUtils;
import com.gxar.common.utils.StringUtils;
import com.gxar.quick.ar.server.base.common.enums.protocol.ArUnityEditorContentTypeEnum;
import com.gxar.quick.ar.server.base.model.protocol.ArColor;
import com.gxar.quick.ar.server.base.model.protocol.ArQuaternion;
import com.gxar.quick.ar.server.base.model.protocol.ArSizeModel;
import com.gxar.quick.ar.server.base.model.protocol.ArVector3;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;

import java.util.Collections;
import java.util.List;

/**
 * Unity编辑器内容信息
 * <a href="https://git.gxar.com/product/product-pc-rebuild-editor-tool-u3d/-/tree/feat-antpctool-document/Documents">点云配置工具面板介绍</a>
 *
 * @author zxh
 * @version 1.0
 * @created 2024/01/02.
 */
@Data
@Slf4j
public class UnityEditorArContentModel {

    /**
     * 内容类型
     */
    private ArUnityEditorContentTypeEnum type;

    /**
     * 资源名称：Hierachy 中 游戏物体的名称
     */
    private String name;

    /**
     * 标记号
     */
    private Long uuid;

    private String url;

    /**
     * 位置坐标
     */
    private ArVector3 position;

    /**
     * Unity原始位置坐标
     */
    private ArVector3 originPosition;

    /**
     * 旋转值
     */
    private ArVector3 rotate;

    /**
     * Unity原始旋转值
     */
    private ArVector3 originRotate;

    /**
     * 旋转四元数
     */
    private ArQuaternion quaternion;

    /**
     * Unity原始旋转四元数
     */
    private ArQuaternion originQuaternion;

    /**
     * 缩放值
     */
    private ArVector3 scale;

    /**
     * Unity原始缩放值
     */
    private ArVector3 originScale;

    /**
     * from DirLight
     */
    @JsonProperty("cast_shadow")
    private Boolean castShadow;

    /**
     * from DirLight
     */
    private Double intensity;

    /**
     * from DirLight
     */
    private ArColor color;

    /**
     * from Image
     */
    @JsonProperty("is_alpha")
    private Boolean isAlpha;

    /**
     * from Image
     */
    @JsonProperty("is_sheet")
    private Boolean isSheet;

    /**
     * from Image
     */
    private UnityEditorArItemSheetModel sheet;

    /**
     * from Video
     */
    @JsonProperty("autoplay")
    private Boolean autoPlay;

    /**
     * from Video
     */
    private Boolean loop;

    /**
     * from Video
     */
    @JsonProperty("abort_audio")
    private Boolean abortAudio;

    /**
     * from Video
     * 单位: ms
     */
    private Double duration;

    /**
     * from Image
     */
    private Double pixelPerUnit;

    /**
     * 原始大小
     */
    private ArSizeModel size;

    public static List<UnityEditorArContentModel> from(String inputConfig) {
        if (StringUtils.isEmpty(inputConfig) || !inputConfig.startsWith("[") || !inputConfig.endsWith("]")) {
            log.warn("build UnityEditorArContentModel error! inputConfig: {}", inputConfig);
            return Collections.emptyList();
        }

        return JacksonUtils.parseList(inputConfig, UnityEditorArContentModel.class);
    }
}
